import uuid
from datetime import datetime
import re
import random
from faker import Faker


class RandomUtil:
    @staticmethod
    def get_uuid(cls):
        """根据时间戳生成 UUID，保证全球唯一"""
        return uuid.uuid1()

    @classmethod
    def get_timestamp(cls):
        # now = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
        now = datetime.now().strftime('%F %T.%f')[:-3]
        return now

    @classmethod
    def get_idcard(cls):
        """ 生成身份证 """
        items = [str(number) for number in range(10)]
        items.extend(['x', 'X'])
        result = []
        for i in range(18):
            item_list = items if i == 17 else items[:-2]
            random_index = random.randint(0, len(item_list)-1)
            result.append(item_list[random_index])
        result = ''.join(result)
        return result


if __name__ == '__main__':
    timestamp = RandomUtil.get_timestamp()
    print(f'测试用例({timestamp})')
    # dict1 = {'name': 'xiaoming', 'age': 18}
    # dict2 = dict((str(k).upper(), v) for k, v in dict1.items())
    # print(f'dict2={dict2}')
    # print(re.match(r'^{.*}$', '{中文}'))
    # params = {'name': '{小明}'}
    # params1 = dict((k, v if not re.match(r'^{.*}$', v) else v[1:-1]) for k, v in params.items())
    # params2 = dict((k, re.sub(r'{|}', '', v)) for k, v in params.items())
    # print(params1)
    # items = [number for number in range(10)]
    # items.extend(['x', 'X'])
    # print(items[-2:])
    # print(random.randint(10, 10))
    # print(RandomUtil.get_idcard())
    fake = Faker(locale='zh_CN')
    name = fake.name()
    print(name)
    print(fake.phone_number())
    print(fake.address())
    print(fake.email())
    print(fake.chrome())
    # 生成身份证号码
    print(fake.ssn())
    print(fake.pydict())
